﻿Imports System.Collections.Generic

Public Class FieldTypeMappings
    Private Shared ReadOnly String_FieldType As New Dictionary(Of String, SharePointField.TypeEnum)
    Private Shared ReadOnly FieldType_String As New Dictionary(Of SharePointField.TypeEnum, String)

    Shared Sub New()
        Add("Boolean", SharePointField.TypeEnum.Bool)
        Add("Choice", SharePointField.TypeEnum.SingleChoice)
        Add("Computed", SharePointField.TypeEnum.Computed)
        Add("Currency", SharePointField.TypeEnum.Currency)
        Add("DateTime", SharePointField.TypeEnum.DateTime)
        Add("File", SharePointField.TypeEnum.File)
        Add("Lookup", SharePointField.TypeEnum.Lookup)
        Add("LookupMulti", SharePointField.TypeEnum.LookupMulti)
        Add("MultiChoice", SharePointField.TypeEnum.MultiChoice)
        Add("Note", SharePointField.TypeEnum.Note)
        Add("Number", SharePointField.TypeEnum.Number)
        Add("Text", SharePointField.TypeEnum.Text)
        Add("URL", SharePointField.TypeEnum.Url)
        Add("User", SharePointField.TypeEnum.User)
        Add("BusinessData", SharePointField.TypeEnum.BusinessData)
        Add("Counter", SharePointField.TypeEnum.Counter)
    End Sub

    Private Shared Sub Add(ByVal spName As String, ByVal spType As SharePointField.TypeEnum)
        String_FieldType.Add(spName, spType)
        FieldType_String.Add(spType, spName)
    End Sub

    Public Shared Function GetFieldName(ByVal t As SharePointField.TypeEnum) As String
        Return FieldType_String(t)
    End Function

    Public Shared Function GetFieldType(ByVal spName As String) As SharePointField.TypeEnum
        Dim res As SharePointField.TypeEnum
        If String_FieldType.TryGetValue(spName, res) Then
            Return res
        Else
            Return SharePointField.TypeEnum.Other
        End If
    End Function

End Class
